package jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.SQLSyntaxErrorException;
import java.sql.Statement;
import java.util.Scanner;

public class PWDDemo {
    public static void main(String[] args){
        Scanner sca=new Scanner(System.in);
        System.out.println("开始修改");
        System.out.println("请输入用户名");
        String username=sca.nextLine();
        System.out.println("开始修改密码");
        String password=sca.nextLine();
        System.out.println("开始修改昵称");
        String nickname=sca.nextLine();
        System.out.println("开始修改年龄");
        int age=Integer.parseInt(sca.nextLine());
        try (Connection conn=DBUtil.getConnection();
        ){
            Statement statement=conn.createStatement();
            String sql="UPDATE user1 " +
                    "SET password='"+password+"',nickname='"+nickname+"',age="+age+" " +
                    "WHERE username='"+username+"'";
            System.out.println(sql);
            int num1=statement.executeUpdate(sql);
            System.out.println("修改完毕");
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
